home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Tools - Objects / C++ / MPW C++ 3.1b1 / Examples / CPlusExamples / Shapes.cp < prev    next >
Text File  |  1989-09-29  |  4KB  |  171 lines

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    MultiFinder-Aware Simple Shapes Sample Application
  4. #
  5. #    CPlusShapesApp
  6. #
  7. #    This file: ShapesApp.cp - Implementation of the TShapes Classes
  8. #
  9. #    Copyright © 1988 Apple Computer, Inc.
  10. #    All rights reserved.
  11. #
  12. #    Versions:    1.0                 3/89
  13. #
  14. #    Components:
  15. #            CPlusShapesApp.make        March 1, 1989
  16. #            TApplicationCommon.h    March 1, 1989
  17. #            TApplication.h            March 1, 1989
  18. #            TDocument.h                March 1, 1989
  19. #            ShapesAppCommon.h        March 1, 1989
  20. #            ShapesApp.h                March 1, 1989
  21. #            ShapesDocument.h        March 1, 1989
  22. #            TApplication.cp            March 1, 1989
  23. #            TDocument.cp            March 1, 1989
  24. #            ShapesApp.cp            March 1, 1989
  25. #            ShapesDocument.cp        March 1, 1989
  26. #            TApplication.r            March 1, 1989
  27. #            ShapesApp.r                March 1, 1989
  28. #
  29. #   There are four main classes in this program. Each of
  30. #   these classes has a definition (.h) file and an
  31. #   implementation (.cp) file.  
  32. #   
  33. #   The TApplication class does all of the basic event
  34. #   handling and initialization necessary for Mac Toolbox
  35. #   applications. It maintains a list of TDocument objects,
  36. #   and passes events to the correct TDocument class when
  37. #   apropriate. 
  38. #   
  39. #   The TDocument class does all of the basic document
  40. #   handling work. TDocuments are objects that are
  41. #   associated with a window. Methods are provided to deal
  42. #   with update, activate, mouse-click, key down, and other
  43. #   events. Some additional classes which implement a
  44. #   linked list of TDocument objects are provided. 
  45. #   
  46. #   The TApplication and TDocument classes together define
  47. #   a basic framework for Mac applications, without having
  48. #   any specific knowledge about the type of data being
  49. #   displayed by the application's documents. They are a
  50. #   (very) crude implementation of the MacApp application
  51. #   model, without the sophisticated view heirarchies or
  52. #   any real error handling. 
  53. #   
  54. #   The TShapesApp class is a subclass of TApplication. It
  55. #   overrides several TApplication methods, including those
  56. #   for handling menu commands and cursor adjustment, and
  57. #   it does some necessary initialization.
  58. #   
  59. #   The TShapesDocument class is a subclass of TDocument. This
  60. #   class contains most of the special purpose code for
  61. #   shape drawing. In addition to overriding several of the
  62. #   TDocument methods, it defines a few additional
  63. #   methods which are used by the TShapesApp class to get
  64. #   information on the document state.  
  65. #
  66. #------------------------------------------------------------------------------*/
  67. #include "Shapes.h"
  68.  
  69. const short width = 40;
  70. const short height = 40;
  71.  
  72. TShape::TShape(Rect *r)
  73. {
  74.     RandomRect(r);
  75. }
  76.  
  77. // Assign a random fBoundRect for the shape.
  78.  
  79. void TShape::RandomRect(Rect *drawRect)
  80. {
  81.     short rand1, rand2;
  82.     
  83.     rand1 = abs(Random()) % (drawRect->right - width);
  84.     fBoundRect.left = rand1;
  85.     rand2 = abs(Random()) % (drawRect->bottom - (height + drawRect->top));
  86.     fBoundRect.top = rand2 + drawRect->top;
  87.     fBoundRect.right = fBoundRect.left + width;
  88.     fBoundRect.bottom = fBoundRect.top + height;
  89. }
  90.  
  91. void TShape::Move(Rect *r)
  92. {
  93.     RandomRect(r);
  94. }
  95.  
  96. TArc::TArc(Rect *r) : (r)        // Calls base class constructor
  97. {
  98.     short rand1, rand2;
  99.  
  100.     rand1 = abs(Random()) % 270;
  101.     fStartAngle = rand1;
  102.     rand2 = abs(Random()) % 270;
  103.     fArcAngle = rand2;
  104. }
  105.  
  106. void TArc::Draw(Pattern pat)
  107. {
  108.     Rect bRect;
  109.  
  110.     bRect = fBoundRect;
  111.     FillArc(&bRect, fStartAngle, fArcAngle, pat);
  112.     FrameArc(&bRect, fStartAngle, fArcAngle);
  113. }
  114.  
  115. void TArc::Erase()
  116. {
  117.     Rect bRect;
  118.  
  119.     bRect = fBoundRect;
  120.     EraseArc(&bRect, fStartAngle, fArcAngle);
  121. }
  122.  
  123.  
  124. TRoundRect::TRoundRect(Rect *r) : (r)        // Calls base class constructor
  125. {
  126.     fOvalWidth = 20;
  127.     fOvalHeight = 15;
  128. }
  129.  
  130. void TRoundRect::Draw(Pattern pat)
  131. {
  132.     Rect bRect;
  133.  
  134.     bRect = fBoundRect;
  135.     FillRoundRect(&bRect, fOvalWidth, fOvalHeight, pat);
  136.     FrameRoundRect(&bRect, fOvalWidth, fOvalHeight); 
  137. }
  138.  
  139. void TRoundRect::Erase()
  140. {
  141.     Rect bRect;
  142.  
  143.     bRect = fBoundRect;
  144.     EraseRoundRect(&bRect, fOvalWidth, fOvalHeight);
  145. }
  146.  
  147.  
  148. TOval::TOval(Rect* r) : (r)        // Calls base class constructor
  149. {
  150.     ;
  151. }
  152.  
  153. void TOval::Draw(Pattern pat)
  154. {
  155.     Rect tempRect = fBoundRect;
  156.     
  157.     FillOval(&tempRect, pat);
  158.     FrameOval(&tempRect);
  159. }
  160.  
  161. void TOval::Erase()
  162. {
  163.     Rect tempRect = fBoundRect;
  164.     
  165.     EraseOval(&tempRect);
  166. }
  167.  
  168.  
  169.  
  170.  
  171.